/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-12-01 10:46:52
 * @LastEditors: 商晓彬
 * @LastEditTime: 2021-12-21 11:36:57
 */
import { Component, Injector, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { finalize } from 'rxjs/operators';
import { MessageService } from '@abp/message/message.service';
import { LazyLoadEvent } from 'primeng/api';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { AssemblyProgressBoardServiceProxy, CommonServiceProxy, SuiteInfoBoardServiceProxy } from '@shared/service-proxies/service-proxies';
import * as moment from 'moment';
import { AssemblyInnerComponent } from './assembly-inner/assembly-inner.component';

@Component({
    selector: 'app-rocket-assembly-kanban',
    templateUrl: './rocket-assembly-kanban.component.html',
    styleUrls: ['./rocket-assembly-kanban.component.less']
})
export class RocketAssemblyKanbanComponent extends AppComponentBase {
    @ViewChild('AssemblyInnerComponent') AssemblyInnerComponent: AssemblyInnerComponent;
    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _assemblyProgressBoardServiceProxy: AssemblyProgressBoardServiceProxy,
        private _commonServiceProxy: CommonServiceProxy,
        private _suiteInfoBoardServiceProxy: SuiteInfoBoardServiceProxy,
    ) {
        super(injector);
    }
    fullScreen = false;
    model = undefined;
    modelOptions = [];
    selectData = [];
    rockName = '';
    chooseIndex = 0;
    topForm = {
        completeHour: undefined, taskHour: undefined,
        hourCompletionSchedule: undefined, completeCount: undefined,
        taskCount: undefined, stepCompletionSchedule: undefined
    };
    downForm = {
        title: undefined, id: undefined,
        completeHour: undefined, taskHour: undefined,
        hourCompletionSchedule: undefined, completeCount: undefined,
        taskCount: undefined, stepCompletionSchedule: undefined
    };
    setTimeoutData() {
        abp.ui.setBusy();
        this._assemblyProgressBoardServiceProxy.getNodeDropListOfTask(
            this.model
        )
            .pipe(finalize(() => { })).subscribe(result => {
                abp.ui.clearBusy();
                this.selectData = result.taskBoardListXJLists;
                this.topForm.completeCount = result.completeCount;
                this.topForm.completeHour = result.completeHour;
                this.topForm.taskHour = result.taskHour;
                this.topForm.hourCompletionSchedule = result.hourCompletionSchedule;
                this.topForm.taskCount = result.taskCount;
                this.topForm.stepCompletionSchedule = result.stepCompletionSchedule;


                this.selectData[this.chooseIndex].isUsed = 1;
                this.downForm.title = this.selectData[this.chooseIndex].name;
                this.downForm.id = this.selectData[this.chooseIndex].id;
                this.downForm.completeCount = this.selectData[this.chooseIndex].completeCount;
                this.downForm.completeHour = this.selectData[this.chooseIndex].completeHour;
                this.downForm.taskHour = this.selectData[this.chooseIndex].taskHour;
                this.downForm.hourCompletionSchedule = this.selectData[this.chooseIndex].hourCompletionSchedule;
                this.downForm.taskCount = this.selectData[this.chooseIndex].taskCount;
                this.downForm.stepCompletionSchedule = this.selectData[this.chooseIndex].stepCompletionSchedule;
            })
    }
    openSon() {
        this.AssemblyInnerComponent.show();
    }
    getLeftDown(item, index) {
        setTimeout(() => {
            this.chooseIndex = index;
            //根据火箭种类获取配套信息
            let oldData = this.selectData;
            // this.selectData = [];
            for (let i = 0; i < oldData.length; i++) {
                const item = oldData[i];
                if (i == index) {
                    item.isUsed = 1;
                    this.downForm.title = item.name;
                    this.downForm.id = item.id;
                    this.downForm.completeHour = item.completeHour;
                    this.downForm.taskHour = item.taskHour;
                    this.downForm.hourCompletionSchedule = item.hourCompletionSchedule;
                    this.downForm.completeCount = item.completeCount;
                    this.downForm.taskCount = item.taskCount;
                    this.downForm.stepCompletionSchedule = item.stepCompletionSchedule;
                } else {
                    item.isUsed = 0;
                }
            }
            let rockName = this.rockName.split('-');
            this.rockName = rockName[0];
            this.rockName = this.rockName + this.getPhotoName(item.name);
        }, 10);
    }
    ngOnInit() {
        setInterval(() => {
            this.setTimeoutData();
        }, 3600000);
        //型号
        abp.ui.setBusy();
        this._suiteInfoBoardServiceProxy.getModelLotNoForBoard(
        )
            .pipe(finalize(() => { })).subscribe(result => {
                this.modelOptions = result;
                this.model = result[0].value;
                this._assemblyProgressBoardServiceProxy.getNodeDropListOfTask(
                    this.model
                )
                    .pipe(finalize(() => { })).subscribe(result => {
                        abp.ui.clearBusy();
                        this.selectData = result.taskBoardListXJLists;
                        this.topForm.completeCount = result.completeCount;
                        this.topForm.completeHour = result.completeHour;
                        this.topForm.taskHour = result.taskHour;
                        this.topForm.hourCompletionSchedule = result.hourCompletionSchedule;
                        this.topForm.taskCount = result.taskCount;
                        this.topForm.stepCompletionSchedule = result.stepCompletionSchedule;
                        let name = '';
                        for (const item of this.selectData) {
                            name = name + item.name;
                            item.isUsed = 0;
                        }
                        this.rockName = this.getTypeName(name);
                        this.rockName = this.rockName + this.getPhotoName(this.selectData[0].name);
                        this.selectData[0].isUsed = 1;
                        this.downForm.title = this.selectData[0].name;
                        this.downForm.id = this.selectData[0].id;
                        this.downForm.completeCount = this.selectData[0].completeCount;
                        this.downForm.completeHour = this.selectData[0].completeHour;
                        this.downForm.taskHour = this.selectData[0].taskHour;
                        this.downForm.hourCompletionSchedule = this.selectData[0].hourCompletionSchedule;
                        this.downForm.taskCount = this.selectData[0].taskCount;
                        this.downForm.stepCompletionSchedule = this.selectData[0].stepCompletionSchedule;
                    });
            });
    }
    getTypeName(name) {
        if (name.indexOf("芯二级") == -1) {
            //无芯二级
            if (name.indexOf("助推Ⅱ") == -1) {
                //无助推
                return 'rock7';
            } else {
                if (name.indexOf("助推Ⅳ") == -1) {
                    //判断有两个助推还是四个助推
                    //两个助推
                    return 'rock4';
                } else {
                    return 'rock1';
                }
            }
        } else {
            //判断是否有新三级
            if (name.indexOf("芯三级") == -1) {
                //不存在芯三级
                if (name.indexOf("助推Ⅱ") == -1) {
                    //无助推
                    return 'rock8';
                } else {
                    //判断几个助推
                    if (name.indexOf("助推Ⅳ") == -1) {
                        //判断有两个助推还是四个助推
                        //两个助推
                        return 'rock5';
                    } else {
                        return 'rock2';
                    }
                }
            } else {
                if (name.indexOf("助推Ⅱ") == -1) {
                    //无助推
                    return 'rock9';
                } else {
                    //判断几个助推
                    if (name.indexOf("助推Ⅳ") == -1) {
                        //判断有两个助推还是四个助推
                        //两个助推
                        return 'rock6';
                    } else {
                        return 'rock3';
                    }
                }
            }
        }
    }
    getPhotoName(name) {
        let type = this.rockName.split('rock');
        switch (type[1]) {
            case '1':
                return this.getType1(name);
            case '2':
                return this.getType2(name);
            case '3':
                return this.getType3(name);
            case '4':
                return this.getType4(name);
            case '5':
                return this.getType5(name);
            case '6':
                return this.getType6(name);
            case '7':
                return this.getType7(name);
            case '8':
                return this.getType8(name);
            case '9':
                return this.getType9(name);
            default:
                return '-1';
        }
    }
    getType1(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '星罩':
                return "-2";
            case '助推Ⅰ':
                return "-3";
            case '助推Ⅱ':
                return "-4";
            case '助推Ⅲ':
                return "-5";
            case '助推Ⅳ':
                return "-6";
            default:
                return "-1";
        }
    }
    getType2(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '芯二级':
                return "-2";
            case '星罩':
                return "-3";
            case '助推Ⅰ':
                return "-4";
            case '助推Ⅱ':
                return "-5";
            case '助推Ⅲ':
                return "-6";
            case '助推Ⅳ':
                return "-7";
            default:
                return "-1";
        }
    }
    getType3(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '芯二级':
                return "-2";
            case '芯三级':
                return "-3";
            case '星罩':
                return "-4";
            case '助推Ⅰ':
                return "-5";
            case '助推Ⅱ':
                return "-6";
            case '助推Ⅲ':
                return "-7";
            case '助推Ⅳ':
                return "-8";
            default:
                return "-1";
        }
    }
    getType4(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '星罩':
                return "-2";
            case '助推Ⅰ':
                return "-3";
            case '助推Ⅱ':
                return "-4";
            default:
                return "-1";
        }
    }
    getType5(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '芯二级':
                return "-2";
            case '星罩':
                return "-3";
            case '助推Ⅰ':
                return "-4";
            case '助推Ⅱ':
                return "-5";
            default:
                return "-1";
        }
    }
    getType6(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '芯二级':
                return "-2";
            case '芯三级':
                return "-3";
            case '星罩':
                return "-4";
            case '助推Ⅰ':
                return "-5";
            case '助推Ⅱ':
                return "-6";
            default:
                return "-1";
        }
    }
    getType7(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '星罩':
                return "-2";
            default:
                return "-1";
        }
    }
    getType8(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '芯二级':
                return "-2";
            case '星罩':
                return "-3";
            default:
                return "-1";
        }
    }
    getType9(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '芯二级':
                return "-2";
            case '芯三级':
                return "-3";
            case '星罩':
                return "-4";
            default:
                return "-1";
        }
    }
    onchange(event) {
        abp.ui.setBusy();
        this._assemblyProgressBoardServiceProxy.getNodeDropListOfTask(
            this.model
        )
            .pipe(finalize(() => { })).subscribe(result => {
                abp.ui.clearBusy();
                this.selectData = result.taskBoardListXJLists;
                this.topForm.completeCount = result.completeCount;
                this.topForm.completeHour = result.completeHour;
                this.topForm.taskHour = result.taskHour;
                this.topForm.hourCompletionSchedule = result.hourCompletionSchedule;
                this.topForm.taskCount = result.taskCount;
                this.topForm.stepCompletionSchedule = result.stepCompletionSchedule;
                let name = '';
                for (const item of this.selectData) {
                    name = name + item.name;
                    item.isUsed = 0;
                }
                this.rockName = this.getTypeName(name);
                this.rockName = this.rockName + this.getPhotoName(this.selectData[0].name);
                this.selectData[0].isUsed = 1;
                this.downForm.title = this.selectData[0].name;
                this.downForm.id = this.selectData[0].id;
                this.downForm.completeCount = this.selectData[0].completeCount;
                this.downForm.completeHour = this.selectData[0].completeHour;
                this.downForm.taskHour = this.selectData[0].taskHour;
                this.downForm.hourCompletionSchedule = this.selectData[0].hourCompletionSchedule;
                this.downForm.taskCount = this.selectData[0].taskCount;
                this.downForm.stepCompletionSchedule = this.selectData[0].stepCompletionSchedule;
            })
    }
    full() {
        if (!this.fullScreen) {
            const docElmWithBrowsersFullScreenFunctions = document.getElementById('main') as HTMLElement & {
                webkitRequestFullscreen(): Promise<void>;
            };
            if (docElmWithBrowsersFullScreenFunctions.requestFullscreen) {
                docElmWithBrowsersFullScreenFunctions.requestFullscreen();
            } else if (docElmWithBrowsersFullScreenFunctions.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
                docElmWithBrowsersFullScreenFunctions.webkitRequestFullscreen();
            }
            this.fullScreen = true;
        } else {
            const docWithBrowsersExitFunctions = document as Document & {
                webkitExitFullscreen(): Promise<void>;
            };
            if (docWithBrowsersExitFunctions.exitFullscreen) {
                docWithBrowsersExitFunctions.exitFullscreen();
            } else if (docWithBrowsersExitFunctions.webkitExitFullscreen) { /* Chrome, Safari and Opera */
                docWithBrowsersExitFunctions.webkitExitFullscreen();
            }
            this.fullScreen = false;
        }
    }
}
